package com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.clazzfile.constantpool.item;

import com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.clazzfile.ClassReader;
import com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.clazzfile.constantpool.ConstantInfo;

public class ConstantUtf8Info implements ConstantInfo {

    private String str;

    @Override
    public void readInfo(ClassReader reader) {
//        int length = reader.readUint16();
        // 前2个字节是数据的长度（32767 三万多个字符，理论上够够的了）
        int length = reader.readU2();
        byte[] bytes = reader.readBytes(length);
        this.str = new String(bytes);
    }

    @Override
    public int tag() {
        return this.CONSTANT_TAG_UTF8;
    }

    public String str(){
        return this.str;
    }

    @Override
    public void showInfo() {
        System.out.println("tag 是：" + this.tag() + ", utf8值是：" + this.str);
    }
}
